<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试文件上传</title>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
</head>
<body>
<div>
<!--    <form>-->
        <input type="text" id="input1">
        <input type="text" id="input2">
        <input type="file" id="file">
        <button type="button" onclick="uploadTestFile()">文件上传</button>
<!--    </form>-->

    <select name="" id="selectTest" onchange="testChange()">
        <option value="">请选择</option>
        <option value="1">值1</option>
        <option value="2">值2</option>
    </select>

</div>
</body>
</html>
<script>
  function uploadTestFile(){
    if ($("#input1").val() == ''){
      alert("请输入");
      return;
    }
    if ($("#input2").val() == ''){
      alert("请输入");
      return;
    }

      let fileInput = $("#file")[0].files[0];
    var formData = new FormData();
    formData.append("file",fileInput)
    formData.append("valOne",$("#input1").val())
    formData.append("valTwo",$("#input2").val())

    // let val1 = $("#input1").val();
    // let val2 = $("#input2").val();
    // formData.append("file",$("#file")[0].files[0]); //生成一对表单属性
    //formData.append("val1",val1);
    //formData.append("val2",val2);
    // formData.append("val1",$("#input1").val());
    // formData.append("val2",$("#input2").val());
    $.ajax({
      url:'/ajaxUploadTest',
      type:'post',
      data:formData,
      cache:false,
      processData:false,
      contentType:false,
      success:function (data){
        console.log(data);
        alert("上传成功");
      }
    })
  }

  function testChange(){
      let text = $("#selectTest option:selected").val();
      alert(text);
  }
</script>
